package com.xiong.bistu.wetchat;

import com.xiong.bistu.wetchat.Core.AppConfig;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * @title RetrofitUtils
 * @description
 * @author Chad
 * @since 17/7/3 下午4:35
 * @modifier
 * @date
 **/

public class RetrofitUtils {
    private static Retrofit userRetrofit;
    private static Retrofit serverRetrofit;
    private static OkHttpClient mOkHttpClient;

    /**
     * 获取Retrofit对象
     *
     * @return
     */
    protected static Retrofit getRetrofit() {
        if (null == mOkHttpClient) {
            mOkHttpClient = OkHttpUtils.getOkHttpClient();
        }
        if(userRetrofit ==null){
            userRetrofit = new Retrofit.Builder()
                    //设置服务器路径
                    .baseUrl(AppConfig.API_SERVER_TEST + "/")
                    //添加转化库，默认是Gson
                    .addConverterFactory(GsonConverterFactory.create())
                    //添加回调库，采用RxJava
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    //设置使用okHttp网络请求
                    .client(mOkHttpClient)
                    .build();
        }
        return userRetrofit;
    }
}
